//
//  ALPCustomHistoryTableViewCell.m
//  AlpFM
//
//  Created by KING on 16/2/26.
//  Copyright © 2016年 Alp. All rights reserved.
//

#import "ALPCustomHistoryTableViewCell.h"

@interface ALPCustomHistoryTableViewCell()
@property (nonatomic, strong) UIImageView *headerView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) UILabel *lastTime;

@end

@implementation ALPCustomHistoryTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}


- (void)createSubViews{
    //图
    self.headerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0.16*SCREEN_WIDTH, 0.16*SCREEN_WIDTH)];
    self.headerView.image = [UIImage imageNamed:@"user"];
    self.headerView.layer.masksToBounds = YES;
    self.headerView.layer.cornerRadius = 0.08*SCREEN_WIDTH;
    self.headerView.center = CGPointMake(SCREEN_WIDTH *0.15, 0.133*SCREEN_WIDTH);
    [self.contentView addSubview:self.headerView];
    
    //下面的小灰条
    UIImageView *downImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0.267*SCREEN_WIDTH-2, SCREEN_WIDTH, 2)];
    downImageView.image = [UIImage imageNamed:@"bot"];
    [self.contentView addSubview:downImageView];
    
    //标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.267*SCREEN_WIDTH, 0.053*SCREEN_WIDTH, 0.667*SCREEN_WIDTH, 0.053*SCREEN_WIDTH)];
    self.titleLabel.text = @"作者标题";
    self.titleLabel.font = [UIFont systemFontOfSize:0.037*SCREEN_WIDTH];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.titleLabel];
    
    //副标题
    self.subtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.267*SCREEN_WIDTH, 0.107*SCREEN_WIDTH, 0.4*SCREEN_WIDTH, 0.053*SCREEN_WIDTH)];
    self.subtitleLabel.text = @"作者副标题";
    self.subtitleLabel.font = [UIFont systemFontOfSize:0.035*SCREEN_WIDTH];
    self.subtitleLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.subtitleLabel];
    
    //上次播放时间
    self.lastTime = [[UILabel alloc] initWithFrame:CGRectMake(0.05*SCREEN_WIDTH+ 0.21*SCREEN_WIDTH, 0.17*SCREEN_WIDTH, 0.4*SCREEN_WIDTH, 0.053*SCREEN_WIDTH)];
    [self.contentView addSubview:self.lastTime];
    self.lastTime.text = @"12765";
    self.lastTime.font = [UIFont systemFontOfSize:0.037*SCREEN_WIDTH];
    self.lastTime.backgroundColor = [UIColor clearColor];
    
}

#pragma mark - 赋值
-(void)setModel:(ALPHistoryModel *)model{
//    if (_model != model) {
//        [_model release];
//        _model = [model retain];
//    }
    _model = model;
    NSURL *url = [NSURL URLWithString:_model.coverLarge];
    [self.headerView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"user"]];
    
    self.titleLabel.text = _model.title;
    self.subtitleLabel.text = _model.nickname;
    
    NSInteger min = _model.lastTime.intValue / 60;
    NSInteger sec = _model.lastTime.intValue % 60;
    self.lastTime.text = [NSString stringWithFormat:@"上次播放到 %02ld:%02ld", (long)min, (long)sec];
    
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
